import { DocumentUtils, IEnvironment } from '@amcax/base';
import { PickerAssembly, PickerMgr } from '@amcax/renderer';
import { cmdMgr } from '@app-base/manager/CmdManager';
import { CadEnvironments } from '@app-cad-env/index';
import ReloadModal from '@app-cad-env/nextcad/widgets/AssistLayer/modals/ReloadModal';
import EnvSwitch from '@app-cad/common/components/EnvSwitch';
import { defaultEventCenter } from '@app-cad/common/events/DefaultEventCenter';
import { eventCenterManager } from '@app-cad/common/events/EventCenterManager';
import { EmptyEventCenter } from './events/EmptyEventCenter';
import CommandBar from './widgets/CommandBar';
import { LeftPanel } from './widgets/LeftPanel';
import { ToolBar } from './widgets/ToolBar';
import { CircleBar } from '@app-cad/common/widgets/CircleBar';

export const productEnvironment: IEnvironment = {
  id: CadEnvironments.Product,
  label: '产品',
  index: 0,
  showViewCube: true,
  init: () => {},
  load: async () => {
    cmdMgr.updateUndoSize();

    const eventCenter = defaultEventCenter(
      PickerMgr.getPicker<PickerAssembly>('assembly'),
    );
    const emptyEventCenter = new EmptyEventCenter();

    eventCenterManager
      .addEventCenter(eventCenter)
      .addEventCenter(emptyEventCenter)
      .switchTo(eventCenter.id);
  },
  unload: async () => {},
  contextMenus: () => [],
  toolBar: () => {
    return DocumentUtils.isReadOnly() ? null : <ToolBar />;
  },
  commandBar: (style: string = 'down') => <CommandBar style={style} />,
  leftTopNavBar: () => <EnvSwitch />,
  leftPanel: () => <LeftPanel />,
  actionBar: () => <></>,
  assistLayer: () => (
    <>
      <ReloadModal />
    </>
  ),
  circleBar: () => {
    return <CircleBar environment={'product_env'} />;
  },
};
